package com.coollang.smartbra.views;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.TextView;

public class CountView extends TextView {
	//动画时长 ms
	  int duration = 1000;
	  float factor  = 5f;
	  public CountView(Context context, AttributeSet attrs) {
	    super(context, attrs);
	  }
	  @SuppressLint("NewApi") public void showNumberWithAnimation(int number) {
	    //修改number属性，会调用setNumber方法
		ObjectAnimator objectAnimator=ObjectAnimator.ofInt(this,"number",0,number);
	    objectAnimator.setDuration(duration);
	    //加速器，从慢到快到再到慢
	    objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
	    objectAnimator.start();
	  }
	  @SuppressLint("NewApi") public void showNumberWithAnimation(float number) {
		  //修改number属性，会调用setNumber方法
	        ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(this,"number",0,number);
	        objectAnimator.setDuration(duration);
	        //加速器，从慢到快到再到慢
	        objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
	        objectAnimator.start();
	    }
	  @SuppressLint("NewApi") public void showNumberWithAnimation(int number,int duration) {
		    //修改number属性，会调用setNumber方法
			ObjectAnimator objectAnimator=ObjectAnimator.ofInt(this,"number",0,number);
		    objectAnimator.setDuration(duration);
		    //加速器，从慢到快到再到慢
		    objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
		    objectAnimator.start();
		  }
	    public void setNumber(float number) {
	        setText(String.format("%1$03.1f",number));
	    }
		  
	  public void setNumber(int number) {
	    setText(Integer.toString(number));
	  }
}
